# coding: utf8

user_id = auth.user.id if auth.user else 0


CITY_SIZE=25
STATE_SIZE=25
newline = '\n'
default_street= T('123 Some Street')
default_city=T('Montréal')
default_province="Québec"
default_country = 'Canada'
default_postal_code= 'H2P 1M5'
default_address = 'street' + newline + default_city + ',' + default_province
default_address_type = '1'

db.define_table('address_type',
    Field('name', label=T("Address Type")),
#    audit_table
    )

db.define_table('address',
    Field('created_by', db.auth_user, default=user_id, writable=False),
    Field('address_type_id', db.address_type,default=default_address_type,
            label=T("Type"),
            writable=False, readable=True),
    Field('address', "text",
            length=255, default=default_street, 
            label=T("Address")),
    Field('city', length=CITY_SIZE, default=default_city, label=T("City")),
    Field('province', length=STATE_SIZE, default=default_province, 
          label=T("Province/State")),
    Field('postal_code', length=8, default=None, label=T("Postal Code"),
          comment=T("Enter the postal or zip code")),
#    Field('address_display', type='text',default=default_address),
#    audit_table
    )


#db.address.donor_id.requires = IS_IN_DB(db,"donor.id","%(name)s")
db.address.created_by.requires = IS_IN_DB(db,"auth_user.id","%(first_name)s")
db.address.address_type_id.requires = IS_IN_DB(db,"address_type.id","%(name)s")
